$().ready(function() {
	validateRule();
	loadSelect();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/settingDemo/employeeinfo/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}

function loadSelect() {

	$.ajax({
		cache : true,
		type : "get",
		url : "/settingDemo/role/allroleinfo",
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			var $roleid = $("#roleid");
			for(var i=0;i<data.length;i++){
				var item = data[i];
				$roleid.append("<option value="+item.id+">"+item.rolename+"</option>")
			}

		}
	});
}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			username : {
				required : true,
				maxlength:20
			},
			employeename:{
				required : true,
				maxlength:20
			},
			gender : {
				required : true
			},
			mobile : {
				digits:true
			},
			email : {
				email:true
			},
			status : {
				required : true
			},
			roleid:{
				required : true
			}
		},
		messages : {
			username : {
				required : icon + "请输入用户名",
				maxlength:icon + "最多输入20个字符"
			},
			employeename:{
				required : icon + "请输入员工姓名",
				maxlength:icon + "最多输入20个字符"
			},
			gender : {
				required : icon + "请选择性别"
			},
			mobile : {
				digits : icon +"手机号码只能是数字"
			},
			email : {
				email:icon +"必须输入正确格式的电子邮件"
			},
			status : {
				required : icon + "请选择状态"
			},
			roleid:{
				required : icon + "请选择角色"
			}
		}
	})
}